/*
 * Copyright (c) 田梓萱 2021-2022.
 * All Rights Reserved.
 * All codes are protected by China's regulations on the protection of computer software, and infringement must be investigated.
 * 版权所有 (c) 田梓萱 2021-2022.
 * 所有代码均受中国《计算机软件保护条例》保护，本项目已获得软著.
 */

package com.xcl.calculator.Ability;

import com.huawei.hms.analytics.HiAnalytics;
import com.huawei.hms.analytics.type.HAReportPolicy;
import com.xcl.calculator.Preference_RW;
import com.xcl.calculator.XLog;
import com.xcl.calculator.slice.CaiDanAbilitySlice;
import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;
import ohos.agp.window.service.WindowManager;
import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;

import java.util.HashSet;
import java.util.Set;

import static com.xcl.calculator.MyApplication.instance_hi;

/**
 * The type Cai dan ability.
 *
 * @author Xcl
 * @date 2022 /1/5
 * @package com.xcl.calculator.Ability
 */
public class CaiDanAbility extends Ability {
    /**
     * The constant label.
     */
    private static final HiLogLabel label = new HiLogLabel(HiLog.LOG_APP, 0x00234, "CaiDanAbility");

    /**
     * 开始
     *
     * @param intent the intent
     */
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        try {
            super.setAbilitySliceAnimator(null);
            super.setTransitionAnimation(0, 0);
            this.getWindow().addFlags(WindowManager.LayoutConfig.MARK_ALLOW_EXTEND_LAYOUT);
            // 打开SDK日志开关
            //HiAnalyticsTools.enableLog();
            instance_hi = HiAnalytics.getInstance(this);
            instance_hi.setUserProfile("user_uuid", Preference_RW.uuid.toString());
            instance_hi.setUserId(instance_hi.getAAID());
            // 创建应用启动上报策略
            final HAReportPolicy appLaunchPolicy = HAReportPolicy.ON_APP_LAUNCH_POLICY;
            // 创建应用切后台上报策略
            final HAReportPolicy moveBackgroundPolicy = HAReportPolicy.ON_MOVE_BACKGROUND_POLICY;
            // 创建定时上报策略
            final HAReportPolicy scheduledTimePolicy = HAReportPolicy.ON_SCHEDULED_TIME_POLICY;
            // 设置定时上报时间周期为600秒
            scheduledTimePolicy.setThreshold(60);//TODO:正式版请改掉
            Set<HAReportPolicy> reportPolicies = new HashSet<>();
            // 添加定时上报策略和应用切后台上报策略和应用启动上报策略
            reportPolicies.add(appLaunchPolicy);
            reportPolicies.add(scheduledTimePolicy);
            reportPolicies.add(moveBackgroundPolicy);
            // 设置应用切后台上报策略和定时上报策略
            instance_hi.setReportPolicies(reportPolicies);
            super.setMainRoute(CaiDanAbilitySlice.class.getName());
            super.setTransitionAnimation(0, 0);
            super.setAbilitySliceAnimator(null);
        } catch (Exception e) {
            XLog.pd_pd = Preference_RW.ff7_r();
            XLog.error(label, e.getMessage());
        }
    }
}
